<?php

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_web_page_wed_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/rss/rss_channel_dbc.class.php');


class RC_DisEn_WP extends TCMS_Admin_Web_Page_WED_UA {
	public function init() {
		parent::init();

		$v = $this->create_view();
		$this->add_view($v);

		$this->wed->add_wed_event_action_pair(new Web_Event_Simple_Int('activate', Tangra_Parameter_Method::GET, 'activate'), 'activate_event');
		$this->wed->add_wed_event_action_pair(new Web_Event_Simple_Int('deactivate', Tangra_Parameter_Method::GET, 'deactivate'), 'deactivate_event');
	}


	protected function activate_event($rc_id) {
		$rc = new RSS_Channel_DBC();
		$dbc = $this->get_dbc();
		if ($rc->load_by_id($dbc, $rc_id)) {
			$rc->set_disabled(false);

			try {
				$dbc->start_trans();
				$rc->save($dbc);
				$dbc->complete_trans();
			} catch (Exception $e) {
				$dbc->fail_trans();
				$dbc->complete_trans();
				throw $e;
			}

			$view = $this->create_redirect_view('admin/modules/tangra_cms/rss/rss_channels.php');
		} else {
			$view = $this->create_redirect_view('record_not_found.php');
		}

		return $view;
	}


	protected function deactivate_event($rc_id) {
		$rc = new RSS_Channel_DBC();
		$dbc = $this->get_dbc();
		if ($rc->load_by_id($dbc, $rc_id)) {
			$rc->set_disabled(true);

			try {
				$dbc->start_trans();
				$rc->save($dbc);
				$dbc->complete_trans();
			} catch (Exception $e) {
				$dbc->fail_trans();
				$dbc->complete_trans();
				throw $e;
			}

			$view = $this->create_redirect_view('admin/modules/tangra_cms/rss/rss_channels.php');
		} else {
			$view = $this->create_redirect_view('record_not_found.php');
		}

		return $view;

	}


	protected function default_event() {
		throw new Tangra_Module_Exception('Unexpected or missing parameters');
	}
}


